import { HttpSrv } from 'lfun-bg-comp';
import { PageParams, PageResult, Result } from '..';

export interface BorrowOut {
  current_district_province_id?: number;
  current_district_city_id?: number;
  current_district_area_id?: number;
  current_region_province_id?: number;
  current_region_city_id?: number;
  current_region_area_id?: number;
  current_unit_name?: string;
  current_unit_id?: number;
  transfer_out_date?: string;
  transfer_reason?: string;
  teacher_id?: any;
}
export interface SearchBorrowParams {
  teacher_name?: string;
  teacher_number?: string;
  teacher_id_type?: string;
  teacher_id_number?: string;
  teacher_gender?: string;
  original_region_area_id?: string;
  original_district_area_id?: string;
  original_unit?: string;
  current_unit_name?: string;
  current_unit_id?: number;
  current_region_area_id?: string;
  approval_name?: string;
  approval_status?: string;
  operation_time?: string;
  approval_time?: string;
}

export interface BorrowRes {
  current_district_province_id?: number;
  current_district_city_id?: number;
  current_district_area_id?: number;
  current_region_province_id?: number;
  current_region_city_id?: number;
  current_region_area_id?: number;
  current_unit_name?: string;
  current_unit_id?: number;
  transfer_in_date?: string;
  transfer_reason?: string;
  teacher_name?: string;
  teacher_number?: string;
  teacher_id_type?: string;
  teacher_id_number?: string;
  teacher_gender?: string;
  original_unit?: string;
  approval_name?: string;
  approval_status?: string;
  operation_time?: string;
  approval_time?: string;
}

// 借出
export const createBorrowOut = (params: BorrowOut): Result<BorrowOut> =>
  HttpSrv().post('/school/v1/teacher-transaction/teacher-borrow-out', params);

export const searchBorrowOutLaunch = (params: PageParams & SearchBorrowParams): Result<PageResult<BorrowRes>> =>
  HttpSrv().get('/school/v1/teacher-transaction/borrow-out-launch', { params });

export const searchBorrowOutApproval = (params: PageParams & SearchBorrowParams): Result<PageResult<BorrowRes>> =>
  HttpSrv().get('/school/v1/teacher-transaction/borrow-out-approval', { params });

// 撤回
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const borrowRevoked = (process_instance_id, teacher_id): Promise<any> =>
  HttpSrv().patch('/school/v1/teacher-transaction/borrow-revoked', { process_instance_id, teacher_id });

export interface GetBorrowTeacherParams {
  teacher_name: string;
  teacher_id_type: string;
  teacher_id_number: string;
}

export const getBorrowTeacher = (params: GetBorrowTeacherParams): Promise<any> =>
  HttpSrv().get('/school/v1/teacher-transaction/teacher-transfer', { params });

export interface BorrowIn {
  teacher_borrow: {
    // 调入校信息
    current_region_area_id?: string;
    current_unit_id?: string;
    current_position?: string;
    // 调出校信息
    original_district_province_id?: string;
    original_district_city_id?: string;
    original_district_area_id?: string;
    original_unit?: string;
    transfer_out_date?: string;
    transfer_reason?: string;
    original_position?: string;
    remark?: string;
    teacher_id?: any;
  };
  add_teacher?: {
    teacher_name?: string;
    teacher_id_type?: string;
    teacher_id_number?: string;
    teacher_gender?: string;
    teacher_date_of_birth?: string;
  };
}
export const createBorrowIn = (params: BorrowIn): Result<BorrowIn> =>
  HttpSrv().post('/school/v1/teacher-transaction/teacher-borrow-in', params);

export const searchBorrowInApproval = (params: PageParams & SearchBorrowParams): Result<PageResult<BorrowRes>> =>
  HttpSrv().get('/school/v1/teacher-transaction/borrow-in-approval', { params });

export const searchBorrowInLaunch = (params: PageParams & SearchBorrowParams): Result<PageResult<BorrowRes>> =>
  HttpSrv().get('/school/v1/teacher-transaction/borrow-in-launch', { params });

// 审核通过
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const borrowApproved = (transfer_details_id: any, approve_reason: string): Promise<any> =>
  HttpSrv().post('/school/v1/teacher-transaction/borrow-approved', {
    params: { transfer_details_id, approve_reason },
  });

// 审核拒绝
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const borrowRejected = (transfer_details_id: any, approve_reason: string): Promise<any> =>
  HttpSrv().post('/school/v1/teacher-transaction/borrow-rejected', {
    params: { transfer_details_id, approve_reason },
  });

// 全部
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const getBorrowTeacherList = (teacher_id: any): Result<Array<BorrowRes>> =>
  HttpSrv().get('/school/v1/teacher-transaction/teacher-borrow-all', { params: { teacher_id } });
